<?php

session_start();

header('Content-Type: text/html; charset=utf-8');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');

require('../config.php');
include('../inc/functions.php');
include('../inc/config.php');
include('../inc/template.php');
include('../inc/user.php');
include('../inc/page.php');
include('../inc/client.php');
include('../inc/plan.php');
include('../inc/contract.php');
include('../lang/pt_BR.php');

$page = new page();
$config = new config();
$client = new client($db->real_escape_string($_POST['client_username']));
$uri = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

if ($client->verify()) {
	$client->activate();
	$refresh = '<meta http-equiv="refresh" content="5;url='.$_POST['client_login_uri'].'">';
	$page->content .= 'Você esta sendo redirecionado para: <a href="'.$_POST['client_login_uri'].'">'.$_POST['client_login_uri'].'</a> em cinco segundos.';
	iptables_refresh(false);
} elseif(isset($_POST['client_login_uri'])) {
	$refresh = '<meta http-equiv="refresh" content="5;url='.$_POST['client_login_uri'].'">';
	$page->content .= '<h2 style="color: red;">Login ou senha incorreto! Tente novamente.</h2>
		Voce sera redirecionado para a tela de login em cinco segundos.';
} else {
	$page->content .= '
		<form action="http://10.0.0.1:82" method="post">
			<fieldset>
				<label>Autenticação</label>
				<input type="hidden" name="client_login_uri" value="'.$uri.'"/>
				<table>
					<tr>
						<th><label for="client_username">Usuário</label></th>
						<th><label for="client_password">Senha</label></th>
					</tr>
					<tr>
						<td><input type="text" id="client_username" name="client_username" value=""/></td>
						<td><input type="password" id="client_password" name="client_password" value=""/></td>
					</tr>
				</table>
				<button type="submit">Entrar</button>
				</fieldset>
			</form>';
}
include('template.php');

?>